function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}
var util = require("../../utils/util.js");
var a = getApp();

Page({
    data: {
        api: a.globalData.api_host,
        data: "",
        nodeData: "",
        sid: "",
        showall: !0,
        isBD: !1,
        summitJM: !1,
        ismore: !0,
        value: "",
        teleShow: !1,
        client: "",
        hotdream: "",
        article: "",
        page: 1,
        tipShow: !1,
        tip: !1,
        jmvalue: "",
        iscollect: !1,
        islike: !1,
        likedata: "",
        collectdata: "",
        backtop: !1
    },
    onLoad: function(t) {
        console.log("options", t); 
        util.putSeo('pages/info/info',t); 
        var e = this, i = t.id, o = t.cate_id;
        e.setData({
            cate_id: o,
            id: i
        });
        var n = e.options.sid || "";
        console.log(o), a.request({
            id: i
        }, function(t) {
            n = t.data[0].node[n - 1] ? n : "", console.log("sid", n);
            var a = e.selectData(n, t.data[0].node);
            e.setData({
                sid: n,
                showall: !n,
                data: t.data[0],
                nodeData: a
            }), setTimeout(function() {
                e.show_tele();
            }, 500), e.onShow();
        }), e.mengjian(), e.getlist(), e.initStatus();
    },
    onShow: function() {
        var t = getCurrentPages();
        this.setData({
            isBD: 1 == t.length
        }), this.data.data;
    },
    onUnload: function() {
        this.history();
    },
    selectData: function(t, a) {
        for (var e = a[t - 1], i = 0; i < a.length; i++) if (i === t - 1) {
            a.unshift(e), a.splice(i + 1, 1);
            break;
        }
        return a;
    },
    mengjian: function() {
        var t = this, e = t.data.cate_id;
        a.request({
            attr: 1,
            ps: 10,
            cate: e,
            detail: 0,
            like: 1,
            order: "level DESC,update_time DESC"
        }, function(a) {
            console.log(a.data), t.setData({
                hotdream: a.data
            });
        });
    },
    formSubmitHandle: function(t) {
        var a = this, e = t.detail.value.keywords;
        if (!e) return a.setData({
            tip: !0,
            tipShow: !0
        }), setTimeout(function() {
            a.setData({
                tip: !1
            }), setTimeout(function() {
                a.setData({
                    tipShow: !1
                });
            }, 300);
        }, 3e3), !1;
        this.setData({
            p: 1,
            value: e,
            search: !0
        }), wx.navigateTo({
            url: encodeURI("/pages/search/search?q=" + e)
        });
    },
    onshowAll: function() {
        this.setData({
            showall: !0,
            ismore: !1
        });
    },
    showForm: function() {
        this.setData({
            summitJM: !0
        });
    },
    textareaInput: function(t) {
        var e = this;
        a.textareaInput(t, e);
    },
    summit: function() {
        wx.navigateTo({
            url: encodeURI("/pages/dashi/dashi?v=" + this.data.jmvalue)
        });
    },
    show_tele: function(t) {
        var a = this;
        wx.createSelectorQuery().select(".outer").boundingClientRect(function(t) {
            var e = t.height;
            if (e < 1e3) a.setData({
                teleShow: !1,
                outerHeight: "auto"
            }); else {
                var i = (e - 1e3) / e, o = Math.ceil(100 * i);
                o && a.setData({
                    teleShow: !0,
                    client: o
                });
            }
        }).exec();
    },
    telesClick: function() {
        this.setData({
            teleShow: !1
        });
    },
    getlist: function() {
        var e = this;
        1 == e.data.page && e.setData({
            article: []
        }), wx.request({
            url: a.globalData.api_host + "article/list",
            method: "GET",
            dataType: "json",
            data: {
                page: e.data.page,
                cate: 66,
                vc: "smart",
                token: "MZnl52boobOx6S01I5lqqCDa6yjxGiKow"
            },
            header: {
                "content-type": "application/json"
            },
            success: function(a) {
                var i = a.data.data.data;
                i.length > 0 && (i.splice(5, 0, {
                    ad: !0
                }), i.splice(11, 0, {
                    ad: !0
                }), e.setData(t({}, "article[" + (e.data.page - 1) + "]", i)), e.data.page += 1);
            },
            fail: function(t) {
                console.log("错误码：" + t.errCode), console.log("错误信息：" + t.errMsg), wx.showToast({
                    title: "数据获取失败",
                    icon: "none"
                });
            }
        });
    },
    viewDetail: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateToSmartProgram({
            appKey: "NE86mbHmO4ekWZYfjdlMyV9ORv91eIXs",
            path: "pages/detail/detail?id=" + a,
            envVersion: "release",
            success: function(t) {
                console.log("navigateToSmartProgram success", t);
            },
            fail: function(t) {
                console.log("navigateToSmartProgram fail", t);
            }
        });
    },
    onReachBottom: function() {
        this.getlist();
    },
    initStatus: function(t) {
        var a = wx.getStorageSync("likedata"), e = wx.getStorageSync("collectdata"), i = this.data.id;
        if (a) {
            var o = this.findElem(a, "id", i);
            this.setData({
                likedata: a,
                islike: o
            });
        }
        if (e) {
            var n = this.findElem(e, "id", i);
            this.setData({
                collectdata: e,
                iscollect: n
            });
        }
    },
    bindCollect: function(t) {
        var a = t.currentTarget.dataset.type, e = wx.getStorageSync(a);
        console.log("collectdata", e), e || (e = []);
        var i = this.data.id, o = this.data.data.title, n = this.data.data.content, s = this.data.cate_id;
        if (this.findElem(e, "id", i)) e = e.filter(function(t) {
            return i !== t.id;
        }); else {
            var l = {};
            l.id = i, l.cate_id = s, l.title = o, l.content = n, l.checked = !1, e.unshift(l);
        }
        wx.setStorageSync(a, e), "collectdata" == a ? this.setData({
            iscollect: !this.data.iscollect
        }) : this.setData({
            islike: !this.data.islike
        });
    },
    history: function(t) {
        var a = wx.getStorageSync("historydata");
        a || (a = []);
        var e = this.getNowFormatDate(), i = this.data.id, o = this.data.data.title, n = this.data.data.content, s = this.data.cate_id;
        if (!this.findElemDate(a, "id", i, "date", e)) {
            var l = {};
            l.id = i, l.cate_id = s, l.title = o, l.content = n, l.date = e, a.unshift(l);
        }
        console.log("historydata", a), wx.setStorageSync("historydata", a);
    },
    findElem: function(t, a, e) {
        for (var i = 0; i < t.length; i++) if (t[i][a] == e) return !0;
        return !1;
    },
    findElemDate: function(t, a, e, i, o) {
        for (var n = 0; n < t.length; n++) if (t[n][a] == e && t[n][i] == o) return !0;
        return !1;
    },
    getNowFormatDate: function() {
        var t = new Date(), a = t.getFullYear(), e = t.getMonth() + 1, i = t.getDate();
        return e >= 1 && e <= 9 && (e = "0" + e), i >= 0 && i <= 9 && (i = "0" + i), a + "-" + e + "-" + i;
    },
    onPageScroll: function(t) {
        var a = !1;
        t.scrollTop >= 100 && (a = !0), this.setData({
            backtop: a
        });
    },
    handleBacktop: function() {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: "梦见" + this.data.data.title+'是什么征兆?-周公解梦',
            content: this.data.data.content,
            path: "/pages/info/info?id=" + this.data.id 
        };
    },
    onShareTimeline(){
        return {
            title: "梦见" + this.data.data.title+'是什么征兆-周公解梦',
            content: this.data.data.content,
            path: "/pages/info/info?id=" + this.data.id
        };
    }
});